package com.kyc.kycxkplaygame.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.SparseBooleanArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.kyc.kycxkplaygame.R;
import com.kyc.kycxkplaygame.greendao.PropInfoBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/5/10.
 */

public class MyBackPageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context mContext;
    private List<PropInfoBean> mData = new ArrayList<>();
    //上拉加载更多
    public static final int PULLUP_LOAD_MORE = 0;
    //正在加载中
    public static final int LOADING_MORE = 1;
    public static final int LOADING_NO = 2;
    //上拉加载更多状态-默认为0
    private int load_more_status = 0;
    private static final int TYPE_HEAD = 0;  //普通Item View
    private static final int TYPE_ITEM = 1;  //普通Item View
    private static final int TYPE_FOOTER = 2;  //底部FootView
    private SparseBooleanArray mSelectedPositions = new SparseBooleanArray();
    private LayoutInflater mInflater;

    public MyBackPageAdapter(Context context) {
        this.mInflater = LayoutInflater.from(context);
        this.mContext = context;
    }

    public void setList(List<PropInfoBean> list) {
        mData.clear();
        mData.addAll(list);
        this.notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ItemViewHolder viewHolder = new ItemViewHolder(mInflater.inflate(R.layout.mybackpage_item, parent, false));
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof ItemViewHolder) {
            ItemViewHolder itemViewHolder = (ItemViewHolder) holder;
            itemViewHolder.setData(position);
        }
    }

    @Override
    public int getItemCount() {
        return mData == null ? 0 : 16;//mData.size();
    }

    /**
     * 进行判断是普通Item视图还是FootView视图
     *
     * @param position
     * @return
     */
    @Override
    public int getItemViewType(int position) {
        // 最后一个item设置为footerView
        /*if (position == 0) {
            return TYPE_HEAD;
        } else *//*if (position + 1 == getItemCount()) {
            return TYPE_FOOTER;
        } else {*/
        return TYPE_ITEM;
        //}
    }

    /**
     * //上拉加载更多
     * PULLUP_LOAD_MORE=0;
     * //正在加载中
     * LOADING_MORE=1;
     * //加载完成已经没有更多数据了
     * NO_MORE_DATA=2;
     *
     * @param status
     */
    public void changeMoreStatus(int status) {
        load_more_status = status;
        notifyDataSetChanged();
    }


    public class ItemViewHolder extends RecyclerView.ViewHolder {

        private final ImageView prop_img;
        private final TextView prop_num;

        public ItemViewHolder(View itemView) {
            super(itemView);
            prop_img = itemView.findViewById(R.id.prop_img);
            prop_num = itemView.findViewById(R.id.prop_num);
        }

        public void setData(int position) {
            if(position < mData.size()) {
                PropInfoBean propInfoBean = mData.get(position);
                prop_img.setVisibility(View.VISIBLE);
                prop_num.setVisibility(View.VISIBLE);
                if (propInfoBean.getPropName().equals("提示")) {
                    prop_img.setImageResource(R.drawable.tishi);
                    prop_num.setText(propInfoBean.getPropNum()+"");
                } else if (propInfoBean.getPropName().equals("炸弹")) {
                    prop_img.setImageResource(R.drawable.zhandan);
                    prop_num.setText(propInfoBean.getPropNum()+"");
                } else if (propInfoBean.getPropName().equals("时间")) {
                    prop_img.setImageResource(R.drawable.time);
                    prop_num.setText(propInfoBean.getPropNum()+"");
                }else if(propInfoBean.getPropName().equals("西柚")){
                    prop_img.setImageResource(R.drawable.welcome_xiyou);
                    prop_num.setText(propInfoBean.getPropNum()+"");
                }else if(propInfoBean.getPropName().equals("青苹果")){
                    prop_img.setImageResource(R.drawable.apple);
                    prop_num.setText(propInfoBean.getPropNum()+"");
                }else if(propInfoBean.getPropName().equals("西瓜")){
                    prop_img.setImageResource(R.drawable.xigua);
                    prop_num.setText(propInfoBean.getPropNum()+"");
                }
            }else {
                prop_img.setVisibility(View.INVISIBLE);
                prop_num.setVisibility(View.INVISIBLE);
            }
        }
    }


    class FootViewHolder extends RecyclerView.ViewHolder {
        TextView pull_to_refresh_loadmore_text;

        public FootViewHolder(View itemView) {
            super(itemView);
            // pull_to_refresh_loadmore_text = (TextView) itemView.findViewById(R.id.pull_to_refresh_loadmore_text);
        }
    }

   /* class HeadViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        public HeadViewHolder(View itemView) {
            super(itemView);

            itemView.findViewById(R.id.htmlcss_btn).setOnClickListener(this);
            itemView.findViewById(R.id.android_btn).setOnClickListener(this);
            itemView.findViewById(R.id.php_btn).setOnClickListener(this);
            itemView.findViewById(R.id.zixun_btn).setOnClickListener(this);
            itemView.findViewById(R.id.linux_btn).setOnClickListener(this);
            itemView.findViewById(R.id.webservice_btn).setOnClickListener(this);
            itemView.findViewById(R.id.book_btn).setOnClickListener(this);
            itemView.findViewById(R.id.mysefl_btn).setOnClickListener(this);
        }

        @Override
        public void onClick(View view) {
            switch (view.getId()) {
                case R.id.htmlcss_btn:
                    mContext.startActivity(new Intent(mContext, HtmlCssActivity.class));
                    break;
                case R.id.android_btn:
                    break;
                case R.id.php_btn:
                    break;
                case R.id.zixun_btn:
                    break;
                case R.id.linux_btn:
                    break;
                case R.id.webservice_btn:
                    break;
                case R.id.book_btn:
                    break;
                case R.id.mysefl_btn:
                    break;
            }
        }
    }*/
}
